/*
 * @Author: CodeHare
 * @Date: 2023-11-21 14:54:20
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2023-12-19 17:59:57
 * @Description: 报障单单据详情
 */
import 'package:get/get.dart';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:yt_devops/components/select_phone_widget.dart';
import 'fault_report_detail_controller.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yt_devops/pages/tasks/component/wrap_widget.dart';
import 'package:yt_devops/pages/tasks/component/title_widget.dart';
import 'package:yt_devops/pages/tasks/component/pic_gallery_widget.dart';
import 'package:yt_devops/pages/tasks/component/basic_info_item_widget.dart';

class FaultReportDetailPage extends GetView<FaultReportDetailController> {
  const FaultReportDetailPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(ResKey.workOrderDetails.tr),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back, color: Colour.black),
          onPressed: () => Get.back(result: true),
        ),
      ),
      body: GetBuilder<FaultReportDetailController>(
        builder: (controller) => ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            WrapWidget(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  TitleWidget(ResKey.baseInfo.tr,
                      titleStyle: TextStyles.f18.boldStyle),
                  ...controller.model.baseInfos
                      .map((e) => BasicInfoItemWidget(e))
                      .toList(),

                  const SizedBox(height: 8),

                  /// 问题描述
                  ...{
                    dividerWidget(),
                    TitleWidget(ResKey.problemStastic.tr),
                    BrnExpandableText(
                      text: controller.model.problemDescription,
                      textStyle: TextStyle(
                        fontSize: 14.sp,
                        color: Colour.mainTextColor,
                      ),
                      maxLines: 4,
                    ),
                  },

                  /// 故障图片
                  if (controller.model.pics != null) ...{
                    dividerWidget(),
                    PicGalleryWidget(controller.model.pics!),
                  },

                  /// 处理人
                  if (controller.model.isShowReceiver) ...[
                    dividerWidget(),
                    TitleWidget(ResKey.processedBy.tr,
                        value: controller.model.handlerName),
                  ],

                  /// 手机
                  if (controller.model.isShowPhone) ...[
                    dividerWidget(),
                    TitleWidget(ResKey.phone.tr, value: controller.model.phone),
                  ],

                  if (controller.model.isShowSuggestion) ...[
                    dividerWidget(),
                    TitleWidget(ResKey.dealAdvice.tr),
                    controller.model.tails!.isEmpty
                        ? const SizedBox()
                        : Text(
                            controller.model.tasilInfos[1].description!,
                            style: TextStyles.f14,
                          ),
                  ],
                ],
              ),
            ),

            /// 任务进度
            WrapWidget(
              padding: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  TitleWidget(ResKey.schedule.tr),
                  for (var i = 0; i < controller.model.tasilInfos.length; i++)
                    BrnStepLine(
                      lineWidth: 1,

                      /// 非第一个是灰色
                      isGrey: controller.model.tasilInfos[i].id == null,

                      /// 最后一个的线条为透明色 做到不显示的效果
                      lineColor: i == controller.model.tasilInfos.length - 1
                          ? Colors.transparent
                          : const Color(0xffeeeeee),
                      contentWidget: Container(
                        padding: EdgeInsets.only(left: 10.w),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Text('${controller.model.tasilInfos[i].name}',
                                style: TextStyles.f14.boldStyle),
                            Padding(
                              padding:
                                  const EdgeInsets.only(top: 20, bottom: 20),
                              child: Text(
                                controller.model.tasilInfos[i].processorName !=
                                        null
                                    ? '${controller.model.tasilInfos[i].processorName}  ${controller.model.tasilInfos[i].createTime!.replaceAll('-', '/')}'
                                    : '',
                                style: TextStyles.lf14,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget dividerWidget() {
    return const Divider(
      color: Color(0xFFEEEEEE),
    );
  }
}
